<template>
  <div>
    <div class="scroll-div_H content">
      <Scene v-if="false"></Scene>
      <div class="text-area">
        <div
          v-for="(item, index) in typeList"
          class="itemList"
          :key="index"
          @click="changeAddress(item)"
        >
          {{ item.type + "(" + item.balance + ")" }}
        </div>
      </div>

      <div class="listData" :key="index" v-for="(item, index) in imgList">
        <template v-if="imageJudge(item)">
          <div class="listData-main">
            <img :src="item.imageUri" alt="" />
            <div class="label_type1">图片</div>
          </div>
          <div class="listData-context">
            <div class="tit">{{ item.imageName.zh }}</div>
            <div class="tip">代币ID: 11</div>
            <div class="describe">{{ item.imageDesc }}</div>
          </div>
        </template>

        <template v-if="mp4Judge(item)">
          <div class="listData-main item-model">
            <video
              id="myVideo"
              :src="item.imageUri"
              @error="videoErrorCallback"
              enable-danmu
              danmu-btn
              controls
            ></video>
            <!-- <Scene></Scene> -->
            <div class="label_type1">视频</div>
          </div>
          <div class="listData-context">
            <div class="tit">{{ item.imageName.zh }}</div>
            <div class="tip">代币ID: 11</div>
            <div class="describe">{{ item.imageDesc }}</div>
          </div>
        </template>

        <template v-if="obgJudge(item)">
          <div class="listData-main item-model">
            <!-- 3d模型 -->
            <Scene></Scene>
            <div class="label_type1">模型</div>
          </div>
          <div class="listData-context">
            <div class="tit">{{ item.imageName.zh }}</div>
            <div class="tip">代币ID: 11</div>
            <div class="describe">{{ item.imageDesc }}</div>
          </div>
        </template>

        <template v-if="musicJudge(item)">
          <div class="listData-main item-model">
            <video
              id="myVideo"
              :src="item.imageUri"
              @error="videoErrorCallback"
              enable-danmu
              danmu-btn
              controls
            ></video>
            <div class="label_type1">音乐</div>
          </div>
          <div class="listData-context">
            <div class="tit">{{ item.imageName.zh }}</div>
            <div class="tip">代币ID: 11</div>
            <div class="describe">{{ item.imageDesc }}</div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script module="three" lang="renderjs">
  // import { login, queryAddress, queryTokenId } from "@/du-server/api.js";
  import Scene from "@/components/Scene.vue";
  import { login ,queryAddress, queryTokenId} from "@/du-server/api.js";

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name:'main',
  data() {
    return {
      typeList: [],
      count: "",
      assetNft: [],
      imgList: [],
    };
  },
  components: {Scene},
  created() {
    login('?ownerAddress=cfx%3Aaap2501fvx1s5cpgz6fw6f4aj7v75ukg0ap16ka4jj').then((res) => {
    console.log(res);
      this.typeList = res.data;
    })

  },
  mounted(){
    this.$nextTick(()=>{
          console.log('渲染');
    })

  },
  //计算属性
  computed: {

  },
  watch: {

  },
  methods: {

      // 判断是否图片
    imageJudge(item) {
      let str = item.imageUri.substr(item.imageUri.lastIndexOf(".") + 1);
      return str === "jpg" || str === "png" || str === "gif";
    },
    // 判断是否视频
    mp4Judge(item) {
      let str = item.imageUri.substr(item.imageUri.lastIndexOf(".") + 1);
      return str === "mp4";
    },
    // 判断是否3d模型
    obgJudge(item) {
      let str = item.imageUri.substr(item.imageUri.lastIndexOf(".") + 1);
      return str === "obj" || str==='fbx' || str === 'glTF';
    },
    // 判断是否音乐
    musicJudge(item) {
      let str = item.imageUri.substr(item.imageUri.lastIndexOf(".") + 1);
      return str === "mp3";
    },

    // 点击查询
    changeAddress(item) {
      console.log(item.address);
      queryAddress(
        item.address,
        "cfx:aap2501fvx1s5cpgz6fw6f4aj7v75ukg0ap16ka4jj"
      ).then((res) => {
        this.assetNft = res.data[1];
        this.count = res.data[0];
        console.log(this.assetNft);
        this.imgList = [];
        this.assetNft.map((subitem) => {
          queryTokenId(item.address, subitem).then((result) => {
            this.imgList.push(result.data);
          });
        });
      });
    },



  },
};
</script>

<style lang="less">
page {
  background-color: #f5f5f5;
}
.text-area {
  display: flex;
  justify-content: start;
  flex-wrap: wrap;
}
.itemList {
  margin: 5px;
  padding: 3px;
  border-radius: 50px;
  border: 1px solid #4b8eff;
  color: #4b8eff;
  font-size: 13px;
}
.listData {
  margin: 20px;
  background-color: #fff;
  border-radius: 15px;

  &-main {
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    display: flex;
    width: 100%;
    height: auto;
    background-color: #eee;
    img {
      width: 100%;
    }
    video {
      width: 100%;
    }
    .label_type1 {
      font-size: 12px;
      min-width: 47px;
      padding: 0 5px;
      text-align: center;
      position: absolute;
      right: 0;
      top: 14px;
      height: 25px;
      line-height: 25px;
      border-radius: 12.5px 0 0 12.5px;
      background-color: #f87c46;
      color: #fff;
      box-sizing: border-box;
    }
  }
  &-context {
    padding: 8px 10px 2px;
    .tit {
      line-height: 25px;
      color: #43406a;
      font-size: 14px;
      font-weight: bold;
    }
    .tip {
      line-height: 25px;
      color: #43406a;
      font-size: 14px;
    }
    .describe {
      color: #43406a;
      font-size: 14px;
    }
  }
}
</style>
